<template>
  <el-menu class="el-menu-demo" mode="horizontal" background-color="#fff" text-color="#000" active-text-color="#fff">
    <div class="head-box">
      <div class="flex-c">
        <i class="buttonimg" :class="collapsed?'el-icon-s-fold':'el-icon-s-unfold'" @click="toggle(collapsed)"></i>
        <el-select style="width:267px;" v-model="value" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </div>
    <div class="submenu flex-c">
      <i class="el-icon-search btnicon"></i>
      <i class="el-icon-bell btnicon"></i>
      <el-avatar size="small" :src="require('../assets/img/avator.png')"></el-avatar>
      <div style="margin: 0 5px;">admin</div>
      <!-- <el-submenu index="2" >
      <template slot="title">超级管理员</template>
      <el-menu-item index="2-1">设置</el-menu-item>
      <el-menu-item @click="content()" index="2-2">个人中心</el-menu-item>
      <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
      </el-submenu> -->
    </div>
    </div>
  </el-menu>
</template>
<script>
import { loginout } from '../api/userMG'
export default {
  name: 'navcon',
  data() {
    return {
      collapsed: true,
      imgshow: require('../assets/img/show.png'),
      imgsq: require('../assets/img/sq.png'),
      user: {},
      options: [
        {
          value: '选项1',
          label: '东南数据中心'
        },
        {
          value: '选项2',
          label: '南方数据中心'
        },
        {
          value: '选项3',
          label: '北方数据中心'
        }],
        value: '选项1'
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.user = JSON.parse(localStorage.getItem('userdata'))
  },
  methods: {
    // 退出登录
    exit() {
      this.$confirm('退出登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          setTimeout(() => {
            this.$store.commit('logout', 'false')
            this.$router.push({ path: '/login' })
            this.$message({
              type: 'success',
              message: '已退出登录!'
            })
          }, 1000)
          // loginout()
          //   .then(res => {
          //     if (res.success) {
          //       //如果请求成功就让他2秒跳转路由
          //       setTimeout(() => {
          //         this.$store.commit('logout', 'false')
          //         this.$router.push({ path: '/login' })
          //         this.$message({
          //           type: 'success',
          //           message: '已退出登录!'
          //         })
          //       }, 1000)
          //     } else {
          //       this.$message.error(res.msg)
          //       this.logining = false
          //       return false
          //     }
          //   })
          //   .catch(err => {
          //     // 获取图形验证码
          //     this.getcode()
          //     this.logining = false
          //     this.$message.error('退出失败，请稍后再试！')
          //   })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 切换显示
    toggle(showtype) {
      this.collapsed = !showtype
      this.$root.Bus.$emit('toggle', this.collapsed)
    }
  }
}
</script>
<style scoped lang="less">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
.head-box{
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 64px;
}
.submenu {
  margin-right: 20px;
}
.buttonimg {
  margin: 0 20px;
  font-size: 30px;
  cursor: pointer;
  color: #727272;
}
// .showimg {
//   width: 26px;
//   height: 26px;
//   position: absolute;
//   top: 17px;
//   left: 17px;
// }
// .showimg:active {
//   border: none;
// }
/deep/.el-header{
  height: 64px !important;
}
.btnicon{
  font-size: 22px;
  margin: 8px;
  font-weight: 500;
  color: #727272;
  cursor: pointer;
}
/deep/.el-submenu__title{
  padding: 0 10px !important;
}
</style>
